//
//  HWRootTabBarController.m
//  HappyWorkingOA
//
//  Created by 李旭杰 on 2017/4/25.
//  Copyright © 2017年 LiXujie. All rights reserved.
//

#import "HWRootTabBarController.h"
#import "HWBaseNavigationController.h"
#import "CZAdditions.h"

@interface HWRootTabBarController ()

@end

static NSString *const kClassKey    = @"rootVCClassString";
static NSString *const kTitleKey    = @"title";
static NSString *const kImgKey      = @"imageName";
static NSString *const kSelImgKey   = @"selectedImageName";

@implementation HWRootTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self setupTabBarUI];
}
#pragma mark --- tabbar 界面 UI 搭建
- (void) setupTabBarUI{
    NSArray *childItemsArray = @[
                                 @{kClassKey  : @"HWWorkSpaceController",
                                   kTitleKey  : @"工作台",
                                   kImgKey    : @"TABAPP",
                                   kSelImgKey : @"TABAPP_S"},
                                 
                                 @{kClassKey  : @"HWContractController",
                                   kTitleKey  : @"通讯录",
                                   kImgKey    : @"TABAdressBook",
                                   kSelImgKey : @"TABAdressBook_S"},
                                 
                                 @{kClassKey  : @"HWMessageController",
                                   kTitleKey  : @"消息",
                                   kImgKey    : @"TABIM",
                                   kSelImgKey : @"TABIM_S"},
                                 
                                 @{kClassKey  : @"HWProfileController",
                                   kTitleKey  : @"我的",
                                   kImgKey    : @"TABME",
                                   kSelImgKey : @"TABME_S"}
                                 ];
    
    [childItemsArray enumerateObjectsUsingBlock:^(NSDictionary *dict, NSUInteger idx, BOOL *stop) {
        UIViewController *vc = [NSClassFromString(dict[kClassKey]) new];
        vc.title = dict[kTitleKey];
        HWBaseNavigationController *nav = [[HWBaseNavigationController alloc] initWithRootViewController:vc];
        UITabBarItem *item = nav.tabBarItem;
        item.title = dict[kTitleKey];
        item.image = [[UIImage imageNamed:[dict objectForKey:kImgKey]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        item.selectedImage = [[UIImage imageNamed:dict[kSelImgKey]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        [self.tabBar setBackgroundColor: [UIColor cz_colorWithHex:0x2c2b31]];
        [item setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor whiteColor]} forState:UIControlStateSelected];
        [self addChildViewController:nav];
    }];
    self.selectedIndex = 0;
}

@end
